#include "SdkConfig.h"

namespace Lit
{
	namespace SdkTools
	{
		Config::Config(const std::string &name )
			: mDebug( name+"_debug" )
			, mRelease( name+"_release" )
			, mName(name)
		{
		}

		Config::Config(const Config& rk) : mDebug( rk.mDebug ), mRelease( rk.mRelease ), mName(rk.mName){}
		
		Config::~Config(void)
		{
		}

		Config& Config::operator=( const Config& rk ){ mName=rk.mName; mRelease=rk.mRelease; mDebug = rk.mDebug; return *this; }
		
		bool Config::hasDependency( const std::string &name ) const{ return mDeps.find(name) != mDeps.end(); }
		Config::Map& Config::getDependencies(){ return mDeps; }
		const Config::Map& Config::getDependencies() const{ return mDeps; }
		Config * Config::getDependency( const std::string &name ){ return hasDependency( name ) ? &mDeps.find(name)->second : NULL; }
		const Config * Config::getDependency( const std::string &name ) const{ return hasDependency( name ) ? &mDeps.find(name)->second : NULL; }
		void Config::addDependency( const Config& dep ){ if( hasDependency( dep.getName() ) ) throw std::logic_error( "Dependency "+dep.getName()+" already exists in configuration "+mName+" !" ); mDeps[dep.getName()] = dep; }
		void Config::removeDependency( const std::string &name ){ 
			for( auto i=mDeps.begin(); i!=mDeps.end(); i++ )
			{
				if( i->first == name )
				{
					mDeps.erase( i );
					return;
				}
			}
		}
		
		const ConfigRef& Config::getDebug() const{ return mDebug; }
		const ConfigRef& Config::getRelease() const{ return mRelease; }
		ConfigRef& Config::getDebug(){ return mDebug; }
		ConfigRef& Config::getRelease(){ return mRelease; }
		
		void Config::setName(const std::string &str){ mName=str; }
		const std::string& Config::getName() const{ return mName; }
	};
};